package com.springIOC.scope;

import com.springIOC.bean.Bean3;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

/**
 * Created by 41579 on 2017/1/10.
 */
public class MyScope1 implements Scope{
    ThreadLocal<Bean3> threadLocal = new ThreadLocal<Bean3>();
    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        System.out.println("MyScope1............");
        if(threadLocal.get()==null){
            threadLocal.set((Bean3)objectFactory.getObject());
        }
        return threadLocal.get();
    }

    @Override
    public Object remove(String name) {
        System.out.println("remove bean............");
        threadLocal.remove();
        return null;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable callback) {

    }

    @Override
    public Object resolveContextualObject(String key) {
        return null;
    }

    @Override
    public String getConversationId() {
        return null;
    }
}
